﻿using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections.ObjectModel;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Wimm.Common.Entities;
using Windows.Storage;

namespace Wimm.DAL.Repositories
{
    public abstract class SqlLightBaseRepository
    {
        protected SQLiteAsyncConnection _connection;

        public static readonly String DbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");

        public SqlLightBaseRepository()
        {
            _connection = new SQLiteAsyncConnection(DbPath);
        }

        public SqlLightBaseRepository(SQLiteAsyncConnection connection)
        {
            _connection = connection;
        }
        public virtual async Task<bool> SeedData()
        {
            return await _connection.CheckIfSeedIsRequired();
        }

        //public async void InitData()
        //{
        //    bool dbExists = true;
        //    try
        //    {
        //        StorageFile file = await ApplicationData.Current.RoamingFolder.GetFileAsync("db.sqlite");
        //    }
        //    catch
        //    {
        //        dbExists = false;
        //    }

        //    if (!dbExists)
        //    {
        //        var result = await _connection.CreateTablesAsync<Icon,ExpenseCategory,IncomeSource,User, Account>();
        //        //var result2 = await _connection.CreateTablesAsync<Transaction,Income, Expense>();
        //    }
        //}
    }
}
